﻿using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WpfApp36
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void btnStart_Click(object sender, RoutedEventArgs e)
        {
            Button btn = (Button)sender;

            DoubleAnimation doubleAnimation = new()
            {
                By = -100,
                Duration = new Duration(TimeSpan.FromSeconds(1)),
                FillBehavior = FillBehavior.Stop,
                RepeatBehavior = new RepeatBehavior(3)
            };

            doubleAnimation.Completed += DoubleAnimation_Completed;
            btn.BeginAnimation(Button.WidthProperty, doubleAnimation);
        }

        private void DoubleAnimation_Completed(object? sender, EventArgs e)
        {
            btnStart.BeginAnimation(Button.WidthProperty, null);//清除属性上的动画
        }
    }
}